﻿using AutoMapper;
using IMES.Common.Domain.GoldIngotModel;
using IMES.Common.Dtos;
using IMES.Common.Infrastructure;
using MediatR;

namespace GoldIngot.API.Application.Commands.SigningWorkCommand
{
    public class SigningWorkCreateHandler : IRequestHandler<SigningWorkCreateCommand, Result>
    {
        private readonly IBaseRepositorys<SigningWork> signingRep;
        private readonly ILogger<SigningWorkCreateHandler> logger;
        private readonly IMapper mapper;

        public SigningWorkCreateHandler(IBaseRepositorys<SigningWork> signingRep, ILogger<SigningWorkCreateHandler> logger, IMapper mapper)
        {
            this.signingRep = signingRep;
            this.logger = logger;
            this.mapper = mapper;
        }

        /// <summary>
        /// 报工添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(SigningWorkCreateCommand request, CancellationToken cancellationToken)
        {
            var quest = new Result() { Code = (int)CodeEnum.success };
            SigningWork signing=mapper.Map<SigningWork>(request);
            var list = signingRep.Add(signing);
            quest.Data = list;
            return quest;
        }
    }
}
